<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryRef" :inline="true" v-show="showSearch" label-width="68px">
      <el-form-item label="指数">
        <el-input
            v-model="queryParams.instrument"
            placeholder="请输入指数"
            clearable
            size="small"
            style="width: 240px"
            @keyup.enter="handleQuery"
        />
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="Search" size="small" @click="handleQuery">搜索</el-button>
        <el-button icon="Refresh" size="small" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>
    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button
            type="warning"
            plain
            icon="Download"
            size="small"
            @click="handleExport"
            v-hasPermi="['marketdata:equity:tidx:tidxInfo:export']"
        >当页导出
        </el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
            type="warning"
            plain
            icon="Download"
            size="small"
            @click="handleExportAll"
            v-hasPermi="['marketdata:equity:tidx:tidxInfo:export']"
        >全量导出
        </el-button>
      </el-col>
    </el-row>

    <xTable ref="indexInfoRef" refId="indexInfoRef" multiple="false" v-loading="loading" :data="fundsList">
      <template #columList>
         <el-table-column label="序号" type="index" width="40"/>
         <el-table-column label="指数代码" align="center" prop="iCode" />
         <el-table-column label="指数名称" align="left" prop="iName" :show-overflow-tooltip="true" />
         <el-table-column label="资产类型" align="center" prop="aType" :show-overflow-tooltip="true" >
           <template #default="scope">
            <dict-tag :options="A_TYPE" :value="scope.row.aType" />
          </template>
        </el-table-column>
        <el-table-column label="交易市场" align="center" prop="mType" :show-overflow-tooltip="true" >
           <template #default="scope">
            <dict-tag :options="M_TYPE" :value="scope.row.mType" />
          </template>
         </el-table-column>
         <el-table-column label="指数编制人" align="left" prop="iAuthor" :show-overflow-tooltip="true" />
         <el-table-column label="初始价格" align="right" prop="iInitprice" :formatter="formartTableP4" />
         <el-table-column label="加权方式" align="center" prop="iWeight">
           <template #default="scope">
             <span>{{ scope.row.iWeight == 1 ? "自定义数量权重" : (scope.row.ACC_RIGHT == 2 ? "自定义市值权重" : (scope.row.ACC_RIGHT == 3 ? "总股本加权" : "流通股加权")) }}</span>
           </template>
         </el-table-column>
         <el-table-column label="指数类型" align="center" prop="iType" >
           <template #default="scope">
             <span>{{ scope.row.iType == 1 ? "市场指数" : (scope.row.iType == 2 ? "自定义指数" : (scope.row.iType == 3 ? "复合指数" :  (scope.row.iType == 4 ? "基础指数市场加权" : (scope.row.iType == 5 ? "基础指数浮动BP" : (scope.row.iType == 6 ? "基础指数剔除成分" : (scope.row.iType == 7 ? "模拟组合" : "SAA基准")))))) }}</span>
           </template>
         </el-table-column>
      </template>
    </xTable>
    <pagination
        v-show="total > 0"
        :total="total"
        v-model:page="queryParams.pageNum"
        v-model:limit="queryParams.pageSize"
        @pagination="getList"
    />
  </div>
</template>

<script setup name="IndexsInfo">
import {getTidxInfosList} from '@/api/marketdata/equity/indexInfo';
import xTable from "@/xquant/base/xTable";
const {proxy} = getCurrentInstance();
const {M_TYPE, A_TYPE, CURRENCY, I_WEIGHT, I_TYPE} = proxy.useDict("M_TYPE", "A_TYPE", "CURRENCY", "I_WEIGHT", "I_TYPE");

const fundsList = ref([]);
const open = ref(false);
const loading = ref(true);
const showSearch = ref(true);
const ids = ref([]);
const single = ref(true);
const multiple = ref(true);
const total = ref(0);
const title = ref("");
const dateRange = ref([]);

const data = reactive({
  queryParams: {
    pageNum: 1,
    pageSize: 20,
    instrument: undefined
  }
});

const {queryParams} = toRefs(data);

/** 查询列表 */
function getList() {
  loading.value = true;
  getTidxInfosList(queryParams.value).then(response => {
    fundsList.value = response.rows;
    total.value = response.total;
    loading.value = false;
  });
}


/** 搜索按钮操作 */
function handleQuery() {
  queryParams.value.pageNum = 1;
  getList();
}


/** 导出按钮操作 */
function handleExport() {
  proxy.download("marketdata/tidxCtroller/export", {
    ...queryParams.value
  }, `指数信息${new Date().getTime()}.xlsx`);
}

/** 导出按钮操作 */
function handleExportAll() {
  proxy.download("marketdata/tidxCtroller/export", Object.assign({
    ...queryParams.value
  }, {pageSize: ''}), `指数信息${new Date().getTime()}.xlsx`);
}

/** 重置按钮操作 */
function resetQuery() {
  queryParams.value.instrument = null;
  queryParams.value.pageNum = 1;
  getList();
}

getList();
</script>
